const Router = require('koa-router')
const { Extend } = require('@/app/models/extend')
const { Auth } = require('@/middleware/auth')
const { NotEmptyValidator } = require('@/utils/validator')
const router = new Router({
  //统一这是前缀
  prefix: '/api/v1/extend' 
})
//新增扩展
router.post('/addExtend',async ctx => {
  const v = await new NotEmptyValidator().validate(ctx,{
    token: 'name'
  })
  Extend.create({
    name: v.get('body.name'),
    page_path: v.get('body.pagePath'),
  })
  ctx.body = global.responseData(null,'新增成功')
})
//查询扩展
router.get('/queryExtend',async ctx => {
  const extend = await Extend.scope('cd').findAll()
  ctx.body = global.responseData(extend)
})

module.exports = router